package com.example.hcd.adapt;

import java.util.ArrayList;

import com.example.hcd.R;
import com.example.hcd.datamanage.NoticeData;
import com.example.hcd.functionactivity.NoticeListActivity;

import android.content.Context;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NoticeListAdapt extends BaseAdapter{
	private ArrayList<NoticeData> myItemList = new ArrayList<NoticeData>();
	private Context context;
	private LayoutInflater mInflate;
	private boolean ishaveXiugai = false;
	public NoticeListAdapt(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
		mInflate = LayoutInflater.from(context);
	}
	
	public void ishaveXugai(boolean ishave)
	{
		ishaveXiugai = ishave;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return myItemList.size();
	}

	@Override
	public NoticeData getItem(int position) {
		// TODO Auto-generated method stub
		return myItemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			convertView = mInflate.inflate(R.layout.notice_list_item, null);
            
        }
		
		final int num =position;
		NoticeData date = getItem(position);
		TextView text;
		text = (TextView) convertView.findViewById(R.id.taskid_name);
		text.setText(date.getCreate_by());

		text = (TextView) convertView.findViewById(R.id.title);
		text.setText(date.getTitle());

		text = (TextView) convertView.findViewById(R.id.create_time);
		text.setText(date.getCreate_time());
		
		if(ishaveXiugai)
		{
			text = (TextView) convertView.findViewById(R.id.notice_modify_btn);
			text.setText("删除");
			text.setVisibility(View.VISIBLE);	
			text.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
//					Toast.makeText(context, "修改暂未开放", Toast.LENGTH_SHORT).show();
					Message msg = new Message();
					msg.arg2 = num;
//			    	mHandler.sendMessage(msg);
					NoticeListActivity.mHandler.sendMessage(msg);
				}
			});
			
		}
		
		  return convertView;     
	}
	public String processStatus(String processStatusValue) {
		String processStatus = "";
		switch (Integer.parseInt(processStatusValue)) {
		case 0:
//			尚未开始 0
//			进行中 1
//			未签收 2
//			办理中 3
//			已结束 9
			processStatus = "尚未开始";
			break;
		case 1:
			processStatus = "进行中";
			break;
		case 2:
			processStatus = "未签收";
			break;
		case 3:
			processStatus = "办理中";
			break;
		case 9:
			processStatus = "已结束";
			break;

		default:
			break;
		}
		
		return processStatus;

	}
	
	public void setList(ArrayList<NoticeData> list) {
        if (myItemList != null) {
        	myItemList.clear();
        	myItemList.addAll(list);
        } else {
        	myItemList = list;
        }
        notifyDataSetInvalidated();
    }
	
	public void addList(ArrayList<NoticeData> list)
	{
		myItemList.addAll(list);
//		notifyDataSetChanged();
	}

}
